<template>
    <edu-dialog title="编辑课程" size="small" :visible.sync="show"
        :confirmBtnText="$t('common.btn.confirm')" :close-on-click-modal="false" v-on="{close, confirm}">
        <el-form :model="condition" ref="from" label-width="140px" label-position="right"
            size="small" label-suffix=":">
           <el-row>
                <el-form-item label="考核方式" prop="examMode">
                    <el-radio-group v-model="condition.examMode">
                        <el-radio label="1">考试</el-radio>
                        <el-radio label="2" style="margin-left:14px">考查</el-radio>
                    </el-radio-group>
                </el-form-item>
           </el-row>
           <el-row>
                <el-form-item label="课程区分" prop="weeksType">
                    <el-radio-group v-model="condition.weeksType">
                        <el-radio label="0">教学周</el-radio>
                        <el-radio label="1">实践周</el-radio>
                    </el-radio-group>
                </el-form-item>
           </el-row>
           <el-row>
                <el-form-item label="是否必修" prop="compulsory">
                    <el-radio-group v-model="condition.compulsory">
                        <el-radio label="1">是</el-radio>
                        <el-radio label="0" style="margin-left:28px">否</el-radio>
                    </el-radio-group>
                </el-form-item>
           </el-row>
           <el-row>
                <el-form-item label="学期" prop="semesters">
                    <el-select v-model="condition.semesters" multiple collapse-tags style="width: 250px">
                        <el-option
                            v-for="item in options.schoolTerm"
                            :key="item.key"
                            :label="item.label"
                            :value="item.key">
                        </el-option>
                    </el-select>
                </el-form-item>
           </el-row>
           <el-row>
                <el-form-item label="备注" prop="remarks">
                            <el-input
                                type="textarea"
                                style="width: 250px"
                                maxlength="250"
                                v-model="condition.remarks">
                            </el-input>
                </el-form-item>
           </el-row>
        </el-form>
    </edu-dialog>
</template>
<script>
export default {
    props: {
        show: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            condition: {
                examMode: '',
                weeksType: '',
                compulsory: '',
                remarks: '',
                semesters: [],
            },
            options: {
                schoolTerm: []
            }
        }
    },
    created() {
        this.init();
    },
    methods: {
        init() {
            this.options.schoolTerm = this.$attrs.schoolTerm || [];
        },
        close() {
            this.$emit('update:show', false);
        },
        confirm() {
            let data = {...this.condition};
            data.semesters = (data.semesters || []).join();
            let flag = Object.values(data).find(item => item !== "");
            if (!flag) {
                data = null;
            }
            this.$emit('confirm', data);
        }
    }
}
</script>